package org.feuyeux.mysql.hello.service;

import java.util.List;
import org.feuyeux.mysql.hello.mysql.entity.User;
import org.feuyeux.mysql.hello.mysql.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserService {

  @Autowired
  private UserMapper userMapper;

  public List<User> selectAll() {
    return userMapper.selectList(null);
  }

  public User selectById(Long id) {
    return userMapper.selectById(id);
  }

  public int addUser(User user) {
    return userMapper.insert(user);
  }

  public int updateUser(User user) {
//    UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
//    updateWrapper.eq("id", user.getId());
//    return userMapper.update(user, updateWrapper);
    return userMapper.updateById(user);
  }

  public int deleteById(Long id){
    return userMapper.deleteById(id);
  }
}
